#ifndef THREAD_H
#define THREAD_H

#include <functional>
#include <string>
#include <atomic>
#include <thread>
#include <memory>

namespace Logger
{
    class Thread
    {
    public:
        using ThreadFunc = std::function<void()>;

        Thread(ThreadFunc, const std::string &name = "");
        ~Thread();

        void start();
        void join();

        static int getThreadNum()
        {
            return sThreadNum;
        }

        const std::string &getName() const
        {
            return this->name_;
        }

        bool getIsStart() const
        {
            return this->isStart_;
        }

        pid_t getTid() const
        {
            return this->tid_;
        }

    private:
        void initDefaultName();

        static std::atomic_int sThreadNum;
        ThreadFunc func_;
        std::string name_;
        bool isStart_;
        bool isJoin_;
        pid_t tid_;
        std::shared_ptr<std::thread> thread_;
    };
} // namespace Logger

#endif // THREAD_H